package com.dragon.mmochat.model.battle;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.dragon.mmochat.model.enumType.MmochatActionType;
import com.dragon.mmochat.model.enumType.MmochatRoleBmpType;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.model.role.MmochatRole;

public class MmochatRoundFrame implements Serializable {
	private static final long serialVersionUID = 7092782842446559767L;

	// 攻方位置
	private byte pos;

	// 系统提示错误信息
	private String errMsg = null;

	// 操作类型
	private MmochatActionType actionType;

	// 命中目标
	List<MmochatHit> targetHit = new ArrayList<MmochatHit>();

	// 本次操作(如攻击操作)后状态变化的角色
	Map<Byte, MmochatRoundStateChange> newRoles_changeState = new ConcurrentHashMap<Byte, MmochatRoundStateChange>(); // 状态改变
	Map<Byte, Integer> newRoles_delRole = new ConcurrentHashMap<Byte, Integer>(); // 删除角色
	Map<Byte, MmochatRoundStateAddRole> newRoles_addRole = new ConcurrentHashMap<Byte, MmochatRoundStateAddRole>(); // 增加角色

	public byte getPos() {
		return pos;
	}

	public void setPos(byte pos) {
		this.pos = pos;
	}

	public MmochatActionType getActionType() {
		return actionType;
	}

	public void setActionType(MmochatActionType actionType) {
		this.actionType = actionType;
	}

	public List<MmochatHit> getTargetHit() {
		return targetHit;
	}

	public void setTargetHit(List<MmochatHit> targetHit) {
		this.targetHit = targetHit;
	}

	public Map<Byte, MmochatRoundStateChange> getNewRoles_changeState() {
		return newRoles_changeState;
	}

	public void setNewRoles_changeState(
			Map<Byte, MmochatRoundStateChange> newRolesChangeState) {
		newRoles_changeState = newRolesChangeState;
	}

	public Map<Byte, Integer> getNewRoles_delRole() {
		return newRoles_delRole;
	}

	public void setNewRoles_delRole(Map<Byte, Integer> newRolesDelRole) {
		newRoles_delRole = newRolesDelRole;
	}

	public Map<Byte, MmochatRoundStateAddRole> getNewRoles_addRole() {
		return newRoles_addRole;
	}

	public void setNewRoles_addRole(
			Map<Byte, MmochatRoundStateAddRole> newRolesAddRole) {
		newRoles_addRole = newRolesAddRole;
	}

	public void addTarget(byte pos, boolean hit) {
		MmochatHit hitObj = new MmochatHit();
		hitObj.setPos(pos);
		hitObj.setHit(hit);
		targetHit.add(hitObj);
	}

	public void addNewRoleState_changeState(byte pos, MmochatRole role) {
		MmochatRoundStateChange state = new MmochatRoundStateChange();
		state.setSmeValue(role.getSmeValue());
		state.setCurPkBlood(role.getCurPkBlood());
		state.setCurPkSprit(role.getCurPkSprit());
		newRoles_changeState.put(pos, state);
	}

	public void addNewRoleState_delRole(byte pos, MmochatRole role) {
		newRoles_delRole.put(pos, role.getId());
	}
	
	public void addNewRoleState_addRole(byte pos, MmochatRole role, String roleName) {
		MmochatRoundStateAddRole newRole = new MmochatRoundStateAddRole();
		newRole.setId(role.getId());
		newRole.setBmpType(role.getBmpType());
		newRole.setName(roleName);
		newRole.setSmeValue(role.getSmeValue());
		newRole.setTotalBlood(role.getTotalBlood());
		newRole.setCurPkBlood(role.getCurPkBlood());
		newRole.setTotalSprit(role.getTotalSprit());
		newRole.setCurPkSprit(role.getCurPkSprit());
		newRole.setSkills(role.getSkills());
		if (role instanceof MmochatPlayer) {
			newRole.setRoleType(MmochatRoundStateAddRole.人物);
		} else {
			newRole.setRoleType(MmochatRoundStateAddRole.宠物);
		}
		newRoles_addRole.put(pos, newRole);
	}

	public void addNewRoleState_addRole(byte pos, MmochatRole role) {
		MmochatRoundStateAddRole newRole = new MmochatRoundStateAddRole();
		newRole.setId(role.getId());
		newRole.setBmpType(role.getBmpType());
		newRole.setName(role.getName());
		newRole.setSmeValue(role.getSmeValue());
		newRole.setTotalBlood(role.getTotalBlood());
		newRole.setCurPkBlood(role.getCurPkBlood());
		newRole.setTotalSprit(role.getTotalSprit());
		newRole.setCurPkSprit(role.getCurPkSprit());
		newRole.setSkills(role.getSkills());
		if (role instanceof MmochatPlayer) {
			newRole.setRoleType(MmochatRoundStateAddRole.人物);
		} else {
			newRole.setRoleType(MmochatRoundStateAddRole.宠物);
		}
		newRoles_addRole.put(pos, newRole);
	}

	public void addNewRoleState_addRole(byte pos, MmochatRole role,
			MmochatRoleBmpType bmp) {
		MmochatRoundStateAddRole newRole = new MmochatRoundStateAddRole();
		newRole.setId(role.getId());
		newRole.setBmpType(bmp);
		newRole.setName(role.getName());
		newRole.setSmeValue(role.getSmeValue());
		newRole.setTotalBlood(role.getTotalBlood());
		newRole.setCurPkBlood(role.getCurPkBlood());
		newRole.setTotalSprit(role.getTotalSprit());
		newRole.setCurPkSprit(role.getCurPkSprit());
		newRole.setSkills(role.getSkills());
		if (role instanceof MmochatPlayer) {
			newRole.setRoleType(MmochatRoundStateAddRole.人物);
		} else {
			newRole.setRoleType(MmochatRoundStateAddRole.宠物);
		}
		newRoles_addRole.put(pos, newRole);
	}

	public String getErrMsg() {
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}

}
